package cn.edu.xidian.untils;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import cn.edu.xidian.R;
import cn.edu.xidian.controller.JsonController;
import cn.edu.xidian.domain.User;

import java.util.ArrayList;

public class UserListViewAdapter extends BaseAdapter {

    private ArrayList<User> userList;
    private Context context;

    public final static int OFFSET = 10000;

    public UserListViewAdapter(){}

    public UserListViewAdapter(ArrayList<User> userList, Context context){
        this.userList = userList;
        this.context = context;
    }

    public ArrayList<User> getUserList() {
        return userList;
    }

    public void setUserList(ArrayList<User> userList) {
        this.userList = userList;
    }

    @Override
    public int getCount() {
        return userList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //加载适配器界面
        convertView = LayoutInflater.from(context).inflate(R.layout.list_button,parent,false);

        //实例化组件
        Button btn = (Button) convertView.findViewById(R.id.btnDetail);

        btn.setText(userList.get(position).getUser_website());
        Log.i("position",position+"");
        btn.setId(position + OFFSET);
        btn.setTransitionName(JsonController.transferToJson(userList.get(position)));
        return convertView;
    }

}
